id: task-194 title: Add graceful port handling for browser command status: Done assignee:
- '@claude' created_date: '2025-07-15' updated_date: '2025-07-16' labels:
- enhancement
- ux
- error-handling dependencies: []
Description
When launching 'backlog browser' command, if the default port is already in use, the application crashes with a cryptic error message instead of gracefully handling the situation by either finding an available port or providing a clear error message with suggestions.
Acceptance Criteria
- [x] Browser command detects when port is already in use
- [x] Clear error message is displayed when port is unavailable
- [x] Command suggests alternative solutions (different port or stop conflicting process)
- [x] Application exits gracefully without cryptic stack traces
- [x] User can specify alternative port via command line flag
Implementation Plan
- Find where browser command starts the server
- Add error handling for EADDRINUSE errors
- Implement graceful error messages
- Test with occupied ports
- Verify --port flag works correctly
Implementation Notes
Approach
Added comprehensive error handling to the BacklogServer.start() method to catch and gracefully handle port conflicts.
Implementation Details
- Error Detection: Wrapped the
Bun.serve()call in a try-catch block - EADDRINUSE Handling: Specifically check for EADDRINUSE error code or "address already in use" message
- User-Friendly Messages: Display clear error message with helpful suggestions:
- Try a different port with example command
- Platform-specific commands to find what's using the port (lsof for macOS/Linux, netstat for Windows)
- Advice to kill the conflicting process
- Graceful Exit: Use
process.exit(1)instead of throwing unhandled exceptions
Modified Files
src/server/index.ts: Added try-catch error handling in the start() method
Testing
Tested by:
- Starting a server on port 6420
- Attempting to start another server on the same port
- Verified graceful error message appears instead of stack trace
- Confirmed --port flag was already implemented and working